package;

import org.flixel.FlxSprite;
import org.flixel.FlxState;
import org.flixel.FlxG;

class MenuState extends FlxState
{
    private var sprite: FlxSprite;
    private var timeToChange: Float;
	private var timeToChangeAcel: Float;//Controla los 7 segundos
	private var acelAng:Float;//Aceleración angular
	
    public override function create(): Void
    {
        timeToChange = 0;
		timeToChangeAcel = 0;
		acelAng = 200;
        sprite = new FlxSprite(Std.random(640),Std.random(480), "assets/data/cara2.png");
        sprite.velocity.x = 60;
        sprite.velocity.y = 70;
        sprite.angularVelocity = 30;
		sprite.maxAngular = 1000; //Velocidad angular máxima
		FlxG.bgColor = 0xff666677;
        add(sprite);
    }

    public override function update(): Void
    {
        super.update();
        if(sprite.x > FlxG.width - sprite.frameWidth){
            sprite.x = FlxG.width - sprite.frameWidth;
            sprite.velocity.x = -sprite.velocity.x;
        }else if (sprite.x < 0){
            sprite.x = 0;
            sprite.velocity.x = -sprite.velocity.x;
        }

        if(sprite.y > FlxG.height - sprite.frameHeight){
            sprite.y = FlxG.height - sprite.frameHeight;
            sprite.velocity.y = -sprite.velocity.y;
        }else if (sprite.y < 0){
            sprite.y = 0;
            sprite.velocity.y = -sprite.velocity.y;
        }

        timeToChange += FlxG.elapsed;
        if (timeToChange >= 5){
            timeToChange = 0;
            sprite.color = 0xff000000 + Std.random(0xffffff); 
        }
		
		timeToChangeAcel += FlxG.elapsed;
		if (timeToChangeAcel >= 7)
		{
				timeToChangeAcel = 0;
				acelAng *= -1;
		}
		
		sprite.angularAcceleration += acelAng;
		
		
		
    }
}